// Copyright (c) 2024，D-Robotics.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/***************************************************************************
* COPYRIGHT NOTICE
* Copyright 2019 Horizon Robotics, Inc.
* All rights reserved.
***************************************************************************/
#ifndef UTILITY_SENSOR_INC_SC231AI_SETTING_H_
#define UTILITY_SENSOR_INC_SC231AI_SETTING_H_

#ifdef __cplusplus
extern "C" {
#endif

/* more data for sc231ai
*
*       如果需要 sc231ai 作为 master，输出 帧同步信号，给其他 sensor 做同步，
*       可能会用到下面的信息。
        0x300a,0x24, //bit[2]=1 fsync_oen
        0x3032,0xa0, //bit[7]=1 vsync_tc_en
        0x3225,0x30, //bit[4]=1 vsync_end_man_en
        {0x3216,0x3217,}上升沿位置  默认为 0x00 0x02，单位为 1行
        {0x322e，0x322f}下降沿位置  默认为 0x00 0x02，单位为 1行

        修改：
        //vsync_end_man_en
        i2ctransfer -y -f 3 w3@0x32 0x32 0x25 0x30
        实测测量 30fps，默认为低电平，高电平时间为 118us
        //修改下降沿位置
        i2ctransfer -y -f 3 w3@0x32 0x32 0x2f 0x03
        默认为低电平，高电平时间为 148us
        //修改下降沿位置
        i2ctransfer -y -f 3 w3@0x32 0x32 0x2f 0x04
        默认为低电平，高电平时间为 178us
        30fps 代码里, lines_per_second = 33750, 则 每行曝光时间为 1s/33750 = 29.6 us
        符合预期
 * */

static uint32_t sc231ai_linear_30fps_init_setting[] = {
        0x0103,0x01,
        0x36e9,0x80,
        0x37f9,0x80,
        0x301f,0x14,
        0x3058,0x21,
        0x3059,0x53,
        0x305a,0x40,
        0x320e,0x04,
        0x320f,0xb0,
        0x3210,0x00,
        0x3211,0x04,
        0x3212,0x00,
        0x3213,0x04,
        0x3250,0x00,
        0x3301,0x0a,
        0x3302,0x20,
        0x3304,0x90,
        0x3305,0x00,
        0x3306,0x68,
        0x3309,0xd0,
        0x330b,0xd8,
        0x330d,0x08,
        0x331c,0x04,
        0x331e,0x81,
        0x331f,0xc1,
        0x3323,0x06,
        0x3333,0x10,
        0x3334,0x40,
        0x3364,0x5e,
        0x336c,0x8e,
        0x337f,0x13,
        0x338f,0x80,
        0x3390,0x08,
        0x3391,0x18,
        0x3392,0xb8,
        0x3393,0x0e,
        0x3394,0x14,
        0x3395,0x10,
        0x3396,0x88,
        0x3397,0x98,
        0x3398,0xf8,
        0x3399,0x0a,
        0x339a,0x0e,
        0x339b,0x10,
        0x339c,0x3c,
        0x33ae,0x80,
        0x33af,0xc0,
        0x33b2,0x50,
        0x33b3,0x14,
        0x33f8,0x00,
        0x33f9,0x68,
        0x33fa,0x00,
        0x33fb,0x68,
        0x33fc,0x48,
        0x33fd,0x78,
        0x349f,0x03,
        0x34a6,0x40,
        0x34a7,0x58,
        0x34a8,0x10,
        0x34a9,0x10,
        0x34f8,0x78,
        0x34f9,0x10,
        0x3619,0x20,
        0x361a,0x90,
        0x3633,0x44,
        0x3637,0x5c,
        0x363c,0xc0,
        0x363d,0x02,
        0x3660,0x80,
        0x3661,0x81,
        0x3662,0x8f,
        0x3663,0x81,
        0x3664,0x81,
        0x3665,0x82,
        0x3666,0x8f,
        0x3667,0x08,
        0x3668,0x80,
        0x3669,0x88,
        0x366a,0x98,
        0x366b,0xb8,
        0x366c,0xf8,
        0x3670,0xb2,
        0x3671,0xa2,
        0x3672,0x88,
        0x3680,0x33,
        0x3681,0x33,
        0x3682,0x43,
        0x36c0,0x80,
        0x36c1,0x88,
        0x36c8,0x88,
        0x36c9,0xb8,
        0x36ea,0x0b,
        0x36eb,0x0c,
        0x36ec,0x5c,
        0x36ed,0x04,
        0x3718,0x04,
        0x3722,0x8b,
        0x3724,0xd1,
        0x3741,0x08,
        0x3770,0x17,
        0x3771,0x9b,
        0x3772,0x9b,
        0x37c0,0x88,
        0x37c1,0xb8,
        0x37fa,0x0b,
        0x37fc,0x10,
        0x37fd,0x04,
        0x3902,0xc0,
        0x3903,0x40,
        0x3909,0x00,
        0x391f,0x41,
        0x3926,0xe0,
        0x3933,0x80,
        0x3934,0x02,
        0x3937,0x6f,
        0x3e00,0x00,
        0x3e01,0x95,
        0x3e02,0x50,
        0x3e08,0x00,
        0x4509,0x20,
        0x450d,0x07,
        0x4837,0x33,
        0x5780,0x76,
        0x5784,0x10,
        0x5787,0x0a,
        0x5788,0x0a,
        0x5789,0x08,
        0x578a,0x0a,
        0x578b,0x0a,
        0x578c,0x08,
        0x578d,0x40,
        0x5792,0x04,
        0x5795,0x04,
        0x57ac,0x00,
        0x57ad,0x00,
        0x36e9,0x27,
        0x37f9,0x27,
};


static uint32_t sc231ai_stream_on_setting[] = {
	0x0100,0x01,
};

static uint32_t sc231ai_stream_off_setting[] = {
	0x0100,0x00,
};

#if 0
typedef struct sc231ai_gain_value_s
{
        uint32_t again;
        uint32_t dgain;
        uint32_t dfgain;
} sc231ai_gain_value_t;
#endif

/* index = 32*log2(gain);
 * isp calculate gain, and driver will receive index.
 *
 * for this sc231ai sensor, we only use one gain lut:
 * gain_value = again * d_gain(1x-2x), and if d_gain < 2.0, we only use d_fine_gain
 * {again, dgain, dfgain}, //[index, gain_value]=again*dgain
*/
static uint32_t sc231ai_gain_lut[] =
{
        0x00200080,//1.0
        0x00210080,
        0x00220080,
        0x00230080,
        0x00240080,
        0x00250080,
        0x00260080,
        0x00270080,
        0x00280080,
        0x00290080,
        0x002a0080,
        0x002b0080,
        0x002c0080,
        0x002d0080,
        0x002e0080,
        0x002f0080,
        0x00300080,
        0x00310080,
        0x00320080,
        0x00330080,
        0x00340080,
        0x00350080,
        0x00360080,
        0x00370080,
        0x00380080,
        0x00390080,
        0x003a0080,
        0x003b0080,
        0x003c0080,
        0x003d0080,
        0x003e0080,
        0x003f0080,
        0x01200080,//2.0
        0x01210080,
        0x01220080,
        0x01230080,
        0x01240080,
        0x01250080,
        0x01260080,
        0x01270080,
        0x01280080,
        0x01290080,
        0x012a0080,
        0x012b0080,
        0x012c0080,
        0x012d0080,
        0x012e0080,
        0x012f0080,
        0x01300080,
        0x01310080,
        0x01320080,
        0x01330080,
        0x01340080,
        0x01350080,
        0x01360080,
        0x01370080,
        0x01380080,
        0x01390080,
        0x013a0080,
        0x013b0080,
        0x80200080,
        0x80210080,
        0x80220080,
        0x80230080,//4.0
        0x80240080,
        0x80250080,
        0x80260080,
        0x80270080,
        0x80280080,
        0x80290080,
        0x802a0080,
        0x802b0080,
        0x802c0080,
        0x802d0080,
        0x802e0080,
        0x802f0080,
        0x80300080,
        0x80310080,
        0x80320080,
        0x80330080,
        0x80340080,
        0x80350080,
        0x80360080,
        0x80370080,
        0x80380080,
        0x80390080,
        0x803a0080,
        0x803b0080,
        0x803c0080,
        0x803d0080,
        0x803e0080,
        0x803f0080,
        0x81200080,
        0x81210080,
        0x81220080,
        0x81230080,//8.0
        0x81240080,
        0x81250080,
        0x81260080,
        0x81270080,
        0x81280080,
        0x81290080,
        0x812a0080,
        0x812b0080,
        0x812c0080,
        0x812d0080,
        0x812e0080,
        0x812f0080,
        0x81300080,
        0x81310080,
        0x81320080,
        0x81330080,
        0x81340080,
        0x81350080,
        0x81360080,
        0x81370080,
        0x81380080,
        0x81390080,
        0x813a0080,
        0x813b0080,
        0x813c0080,
        0x813d0080,
        0x813e0080,
        0x813f0080,
        0x83200080,
        0x83210080,
        0x83220080,
        0x83230080,//16.0
        0x83240080,
        0x83250080,
        0x83260080,
        0x83270080,
        0x83280080,
        0x83290080,
        0x832a0080,
        0x832b0080,
        0x832c0080,
        0x832d0080,
        0x832e0080,
        0x832f0080,
        0x83300080,
        0x83310080,
        0x83320080,
        0x83330080,
        0x83340080,
        0x83350080,
        0x83360080,
        0x83370080,
        0x83380080,
        0x83390080,
        0x833a0080,
        0x833b0080,
        0x833c0080,
        0x833d0080,
        0x833e0080,
        0x833f0080,
        0x87200080,
        0x87210080,
        0x87220080,
        0x87230080,//32.0
        0x87240080,
        0x87250080,
        0x87260080,
        0x87270080,
        0x87280080,
        0x87290080,
        0x872a0080,
        0x872b0080,
        0x872c0080,
        0x872d0080,
        0x872e0080,
        0x872f0080,
        0x87300080,
        0x87310080,
        0x87320080,
        0x87330080,
        0x87340080,
        0x87350080,
        0x87360080,
        0x87370080,
        0x87380080,
        0x87390080,
        0x873a0080,
        0x873b0080,
        0x873c0080,
        0x873d0080,
        0x873e0080,
        0x873f0080,
        0x8f200080,
        0x8f210080,
        0x8f220080,
        0x8f230080,//64.0
        0x8f240080,
        0x8f250080,
        0x8f260080,
        0x8f270080,
        0x8f280080,
        0x8f290080,
        0x8f2a0080,
        0x8f2b0080,
        0x8f2c0080,
        0x8f2d0080,
        0x8f2e0080,
        0x8f2f0080,
        0x8f300080,
        0x8f310080,
        0x8f320080,
        0x8f330080,
        0x8f340080,
        0x8f350080,
        0x8f360080,
        0x8f370080,
        0x8f380080,
        0x8f390080,
        0x8f3a0080,
        0x8f3b0080,
        0x8f3c0080,
        0x8f3d0080,
        0x8f3e0080,
        0x8f3f0080,//128.0
        0x8f3f0080,
        0x8f3f0084,
        0x8f3f0088,
        0x8f3f008c,
        0x8f3f0090,
        0x8f3f0094,
        0x8f3f0098,
        0x8f3f009c,
        0x8f3f00a0,
        0x8f3f00a4,
        0x8f3f00a8,
        0x8f3f00ac,
        0x8f3f00b0,
        0x8f3f00b4,
        0x8f3f00b8,
        0x8f3f00bc,
        0x8f3f00c0,
        0x8f3f00c4,
        0x8f3f00c8,
        0x8f3f00cc,
        0x8f3f00d0,
        0x8f3f00d4,
        0x8f3f00d8,
        0x8f3f00dc,
        0x8f3f00e0,
        0x8f3f00e4,
        0x8f3f00e8,
        0x8f3f00ec,
        0x8f3f00f0,
        0x8f3f00f4,
        0x8f3f00f8,
        0x8f3f00fc,
        0x8f3f0180,
        0x8f3f0184,
        0x8f3f0188,
        0x8f3f018c,
};

#ifdef __cplusplus
}
#endif

#endif  //UTILITY_SENSOR_INC_SC231AI_SETTING_H_